package com.pro.springbootshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pro.springbootshop.entity.HistoryOrder;
import com.pro.springbootshop.entity.Wares;
import org.apache.ibatis.annotations.*;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface HistoryOrderMapper extends BaseMapper<HistoryOrder> {
    @Select("select * from history_order where  (seller_id=#{sellerId} or #{sellerId}=#{admin} ) limit #{pageNo},#{limit}")
    @Results(
            {
                    @Result(column = "history_order_id",property = "historyOrderId"),
                    @Result(column = "wares_id",property = "waresId"),
                    @Result(column = "buyer_id",property = "buyerId"),
                    @Result(column = "seller_id",property = "sellerId"),
                    @Result(column = "wares_number",property = "waresNumber"),
                    @Result(column = "finish_time",property = "finishTime"),
                    @Result(column = "order_state",property = "orderState"),
                    @Result(column = "wares_id",property = "wares",javaType = Wares.class,
                            one=@One(select = "com.pro.springbootshop.mapper.WaresMapper.selectById")
                    )
            }
    )
    List<HistoryOrder> sellerGetHistoryOrder(@Param("pageNo") int pageNo,@Param("limit") int limit,@Param("sellerId") String sellerId, @Param("admin") String admin);
    @Select("select * from history_order where  (seller_id=#{sellerId} or #{sellerId}=#{admin} )")
    List<HistoryOrder> sellerGetHistoryOrderCounts(@Param("sellerId") String sellerId,@Param("admin") String admin);
    @Select("select * from history_order where buyer_id=#{buyerId} and (seller_id=#{sellerId} or #{sellerId}=#{admin} ) limit #{pageNo},#{limit}")
    @Results(
            {
                    @Result(column = "history_order_id",property = "historyOrderId"),
                    @Result(column = "wares_id",property = "waresId"),
                    @Result(column = "buyer_id",property = "buyerId"),
                    @Result(column = "seller_id",property = "sellerId"),
                    @Result(column = "wares_number",property = "waresNumber"),
                    @Result(column = "finish_time",property = "finishTime"),
                    @Result(column = "order_state",property = "orderState"),
                    @Result(column = "wares_id",property = "wares",javaType = Wares.class,
                            one=@One(select = "com.pro.springbootshop.mapper.WaresMapper.selectById")
                    )
            }
    )
    List<HistoryOrder> getHistoryOrderByBuyerId(@Param("pageNo") int pageNo, @Param("limit") int limit,@Param("buyerId")  String buyerId,@Param("sellerId") String sellerId,@Param("admin") String admin);
    @Select("select * from history_order  where buyer_id=#{buyerId} and (seller_id=#{sellerId} or #{sellerId}=#{admin} )")
    List<HistoryOrder> getHistoryOrderCountsByBuyerId(@Param("buyerId") String buyerId,@Param("sellerId") String sellerId,@Param("admin") String admin);
    @Select("select * from history_order where buyer_id=#{buyerId} and history_order_state=1")
    @Results(
            {
                    @Result(column = "history_order_id",property = "historyOrderId"),
                    @Result(column = "wares_id",property = "waresId"),
                    @Result(column = "buyer_id",property = "buyerId"),
                    @Result(column = "seller_id",property = "sellerId"),
                    @Result(column = "wares_number",property = "waresNumber"),
                    @Result(column = "finish_time",property = "finishTime"),
                    @Result(column = "order_state",property = "orderState"),
                    @Result(column = "wares_id",property = "wares",javaType = Wares.class,
                            one=@One(select = "com.pro.springbootshop.mapper.WaresMapper.selectById")
                    )
            }
    )
    List<HistoryOrder> getHistoryOrderForAfterSales(@Param("buyerId") String buyerId);
}
